#define _CRT_SECURE_NO_WARNINGS   1

#include<iostream>
#include<string>
using namespace std;

int Stack[100000];
int top = -1;
int main()
{
	int n, x;
	cin >> n;
	while (n--)
	{
		string s;
		cin >> s;
		if (s == "push")
		{
			cin >> x;
			Stack[++top] = x;
		}
		if (s == "pop")
		{
			if (top == -1)
				cout << "error" << endl;
			else
			{
				cout << Stack[top] << endl;
				top--;
			}
		}
		if (s == "top")
		{
			if (top == -1)
				cout << "error" << endl;
			else
			{
				cout << Stack[top] << endl;
			}
		}
	}
	return 0;
}